<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>地图选址</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <meta content="initial-scale=1.0, user-scalable=no" name="viewport">
    <meta content="IE=Edge" http-equiv="X-UA-Compatible">
    <style>
        body,
        html,
        #container {
            overflow: hidden;
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
    <script src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=ErvyOA38YNoOZzrryZUwLmhYPujyidGy"></script>
</head>
<body>
<div id="container"></div>
</body>
</html>
<script src="./assets/js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script>

    var map = new BMapGL.Map('container');
    var point = new Map();
    var marker = new Map();
    map.centerAndZoom(new BMapGL.Point(114.28283, 30.671179), 7);
    $.ajax({
        type: "get",
        contentType: 'application/json',
        url: "/api/getAllLocation",
        dataType: 'json',
        success: function (data) {
            if (data.code === 200) {

                for (var i = 0; i < data.data.length; i++) {
                    var longitude = data.data[i].longitude;
                    var latitude = data.data[i].latitude;
                    var name = data.data[i].name;
                    point.set(i, new BMapGL.Point(longitude, latitude));
                    // 创建点标记
                    marker.set(i, new BMapGL.Marker(point.get(i)));
                    map.addOverlay(marker.get(i));
                    var opts = {
                        position: point.get(i), // 指定文本标注所在的地理位置
                        offset: new BMapGL.Size(30, -30) // 设置文本偏移量
                    };
// 创建文本标注对象
                    var label = new BMapGL.Label('<a href="/login?province=' + data.data[i].province + '">' + name + '</a>', opts);
// 自定义文本标注样式
                    label.setStyle({
                        color: 'blue',
                        borderRadius: '5px',
                        borderColor: '#ccc',
                        padding: '10px',
                        fontSize: '16px',
                        height: '30px',
                        lineHeight: '30px',
                        fontFamily: '微软雅黑'
                    });
                    map.addOverlay(label);

                }
            } else {
                layer.alert(data.msg, {icon: 2}, function (index) {
                    layer.close(index);
                });
            }
        }
    })
</script>